/*
This file is part of La Linea.

La Linea is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

La Linea is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with La Linea.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "PropertyItemModel.h"

PropertyItemModel::PropertyItemModel(QObject * parent) : QStandardItemModel(0,2, parent) {
			_currentAnimation = 0;
			_currentNode = 0;
			_mode = NONE;
}

void PropertyItemModel::setAnimation(Animation* a){
	_currentAnimation = a;
}

void PropertyItemModel::setNode(Node* n){
	_currentNode = n;
}
	
void PropertyItemModel::setMode(PropertyListMode m){
	_mode = m;
}
	
void PropertyItemModel::update(){ // Has to be cleaned
	clear();

	switch(_mode) {
		case NONE:
			break;
		case ANIMATION:
			if(_currentAnimation){
				// Name
				QStandardItem* left_name = new QStandardItem(QString("Name"));
				left_name->setFlags(left_name->flags() & ~Qt::ItemIsEditable);
				left_name->setSelectable(false);
				QStandardItem* right_name = new QStandardItem(QString("%0").arg(_currentAnimation->getName().c_str()));
				
				// Frame duration
				QStandardItem* left_duration = new QStandardItem(QString("Frame duration"));	
				left_duration->setFlags(left_duration->flags() & ~Qt::ItemIsEditable);
				left_duration->setSelectable(false);
				QStandardItem* right_duration = new QStandardItem(QString("%0").arg(_currentAnimation->getFrameDuration()));
				
				this->insertRow(this->rowCount());
				this->setItem(0,0,left_name);
				this->setItem(0,1,right_name); 
				this->insertRow(this->rowCount());
				this->setItem(1,0,left_duration);
				this->setItem(1,1,right_duration);
			}
			break;
		case NODE:
			if(_currentNode){
				// Pos x
				QStandardItem* left_x = new QStandardItem(QString("x"));
				left_x->setFlags(left_x->flags() & ~Qt::ItemIsEditable);
				left_x->setSelectable(false);
				QStandardItem* right_x = new QStandardItem(QString("%0").arg(_currentNode->_pos.x*20));
				
				// Pos y
				QStandardItem* left_y = new QStandardItem(QString("y"));	
				left_y->setFlags(left_y->flags() & ~Qt::ItemIsEditable);
				left_y->setSelectable(false);
				QStandardItem* right_y = new QStandardItem(QString("%0").arg(_currentNode->_pos.y*20));
				
				// Thickness
				QStandardItem* left_thickness = new QStandardItem(QString("Thickness"));	
				left_thickness->setFlags(left_thickness->flags() & ~Qt::ItemIsEditable);
				left_thickness->setSelectable(false);
				QStandardItem* right_thickness = new QStandardItem(QString("%0").arg(_currentNode->_size));
				
				this->insertRow(this->rowCount());
				this->setItem(0,0,left_x);
				this->setItem(0,1,right_x); 
				this->insertRow(this->rowCount());
				this->setItem(1,0,left_y);
				this->setItem(1,1,right_y);
				this->insertRow(this->rowCount());
				this->setItem(2,0,left_thickness);
				this->setItem(2,1,right_thickness);
			}
			break;
	}
}